<template>
  <!-- 采购订单 -->
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" @search="getStatistics" @selection-change="e => selection = e"
      ref="SuperTablePage">
      <template v-slot:action-right>
        <el-upload ref="upload" :show-file-list="false" action="/oms-api/purchase/OmsPurchaseOrderRpc/importExcel.json"
          style="display: inline;" :on-success="uploadExcelSuccess" :on-error="uploadExcelError">
          <el-button slot="trigger" style="margin-left: 10px;" size="mini">{{ $tt('label_import') }}</el-button>
        </el-upload>
      </template>
    </ex_super_table_page>
    <auditDialog ref="auditDialog" @submit="reload" />
    <remarkDialog ref="remarkDialog" />

    <!-- 添加运单号 -->
    <addTrackingNumberDialog ref="addTrackingNumberDialog" @reload="reload" />

    <!-- 取消采购订单 -->
    <ex_super_dialog_form ref="cancelPurchaseOrderDialog" v-bind="cancelPurchaseOrderDialog"
      @afterSubmitSuccess="reload()">
    </ex_super_dialog_form>

    <!-- 终止订单 -->
    <ex_super_dialog_form ref="terminationDialog" v-bind="terminationDialog" @afterSubmitSuccess="reload()">
    </ex_super_dialog_form>

    <!-- 申请付款 -->
    <applyPayDialog ref="applyPayDialog" @submit="reload" />

    <!-- 同步订单 -->
    <synOrderDialog ref="synOrderDialog" @submit="reload" />
  </div>
</template>

<script>
import superTablePageFunction from "@/mixin/super-table-page-function";
import page_table_model_manage from "@/mixin/page_table_model_manage";
import emitOnFunction from "@/mixin/emit-on-function";
import auditDialog from "@/page/oms/purchase/dialog/audit_dialog"
import remarkDialog from "@/page/oms/purchase/dialog/remark_dialog"
import addTrackingNumberDialog from "@/page/oms/purchase/dialog/add_tracking_number_dialog"
import applyPayDialog from "@/page/oms/purchase/dialog/apply_pay_dialog"
import select_file_temp from "@/component/base/select_file_temp";
import synOrderDialog from "../dialog/syn_order_dialog.vue"

let emitKey = "oms>purchase>purchase_order";

export default {
  title: 'label_purchase_purchase_order',
  components: {
    auditDialog,
    remarkDialog,
    addTrackingNumberDialog,
    applyPayDialog,
    synOrderDialog
  },
  mixins: [
    superTablePageFunction,
    emitOnFunction(emitKey),
    page_table_model_manage,
  ],
  props: {
  },
  data() {
    return {
      countByStatus: {
        draftCount: 0,
        waitAuditCount: 0,
        waitArrivalCount: 0,
        waitReceivingCount: 0,
        arrivedWarehouseCount: 0,
        completedCount: 0,
        canceledCount: 0,
        terminateCount: 0,
      },
      status_map: {
        "DRAFT": 'draftCount',
        'WAIT_AUDIT': 'waitAuditCount',
        "WAIT_ARRIVAL": 'waitArrivalCount',
        "WAIT_RECEIVING": 'waitReceivingCount',
        "ARRIVED_WAREHOUSE": 'arrivedWarehouseCount',
        "COMPLETED": 'completedCount',
        "CANCELED": 'canceledCount',
        "TERMINATE": 'terminateCount',
      },
      status: '',
      option: {
        search: {
          default: { status: "" },
          resetFieldFun: (def, org) => { def.status = org.status; return def },
          // formDataHandle: (data) => {
          //   return data
          // },
          model: [
            {
              key: 'status', label: 'label_status', itemClass: "w_fill",
              type: 'select', enum: 'PurchaseOrderStatusEnum',
              render: (h, { data }) => {
                const list = Object.keys(this.status_map)
                  .map(it => (
                    <el-radio-button key={it} label={it}>
                      {this.$enumShow(it, 'PurchaseOrderStatusEnum')}({this.countByStatus[this.status_map[it]]})
                    </el-radio-button>
                  ))
                return (<el-radio-group value={data.status}
                  onInput={e => {
                    this.$set(data, 'status', e)
                    this.status = e
                    this.$refs.SuperTablePage.loadDataForSearch()
                  }}>
                  <el-radio-button key="" label="">
                    {this.$tt("label_all")}
                  </el-radio-button>
                  {list}
                </el-radio-group>
                )
              }
            },
            { label: "label_customer", key: "customerId", type: 'common_customer_choose' },
            {
              label: "label_supplier",
              key: "supplierId",
              type: "supplier_select_input"
            },
            {
              label: "label_purchase_purchase_type",
              key: "purchaseType",
              type: "select",
              enum: "PurchasePlatformTypeEnum",
            },
            { label: "label_sku", key: "skuId", type: "sku_selec_input" },
            {
              label: "label_platform_order_1688",
              key: "platformOrderNo",
            },
            {
              label: "label_purchase_order_code",
              key: "code",
            },
            {
              label: "label_purchase_receiving_warehouse",
              key: "warehouseId",
              type: "base_warehouse_select",
            },
            // {
            //   label: "草稿审核",
            //   key: "auditStatus",
            //   type: "select",
            //   enum: "PurchaseAuditStatusEnum",
            // },
            {
              label: "label_change_status",
              key: "changeStatus",
              type: "select",
              enum: "PurchaseAuditStatusEnum",
            },
            {
              label: "label_purchase_payment_status",
              key: "paymentStatus",
              type: "select",
              enum: "PurchaseAuditStatusEnum",
            },
          ],
        },
        action: [
          {
            label: "label_purchase_consolidated_purchase_order",
            if: () => this.status === 'DRAFT',
            auth: "oms_purchase_supplier_edit",
            click: () => this.merge(),
          },
          {
            label: "label_supplier_batch_remove",
            if: () => ['DRAFT'].includes(this.status),
            auth: "oms_purchase_supplier_edit",
            click: () => {
              this.batchFunc('/oms-api/purchase/OmsPurchaseOrderRpc/delete.json', this.$tt('label_purchase_batch_delete_affirm'))
            },
          },
          {
            label: "label_purchase_batch_submission_review",
            if: () => ['DRAFT'].includes(this.status),
            auth: "oms_purchase_supplier_edit",
            click: () => {
              this.batchFunc('/oms-api/purchase/OmsPurchaseOrderRpc/submitBatchDraft.json', this.$tt('label_purchase_batch_submission_review_affirm'))
            },
          },
          {
            label: "label_purchase_batch_approval",
            if: () => ['WAIT_AUDIT'].includes(this.status),
            auth: "oms_purchase_supplier_edit",
            click: () => {
              this.batchFunc('/oms-api/purchase/OmsPurchaseOrderRpc/passBatchDraft.json', this.$tt('label_purchase_batch_approval_affirm'))
            },
          },
          {
            label: "label_purchase_batch_rejection_review",
            if: () => ['WAIT_AUDIT'].includes(this.status),
            auth: "oms_purchase_supplier_edit",
            click: () => {
              this.batchFunc('/oms-api/purchase/OmsPurchaseOrderRpc/rejectBatchDraft.json', this.$tt('label_purchase_batch_rejection_review_affirm'))
            },
          },
        ],
        actionExtra: [
          {
            label: "label_sync_order_1688",
            click: () => this.syncOrder(),
          },
          {
            label: "label_purchase_order_creation",
            click: () => {
              this.$router.push({
                path: "/page/oms/purchase/purchaseManage/purchase_order_creation",
                query: { emitKey },
              });
            },
          },
          {
            label: "label_export",
            click: this.exportExcel,
          },
          {
            // label: 'label_download_import_template',
            render: (h, { data, item }) => {
              return h(select_file_temp, {
                props: {
                  service: "OMS",
                  module: "PURCHASE_ORDER",
                  label: this.$t("label_download_import_template"),
                },
              });
            },
          },
        ],

        table: {
          url: "/oms-api/purchase/OmsPurchaseOrderRpc/selectPage.json",
          attrs: {},
          model: this.init_table_model(),
        },
      },

      cancelPurchaseOrderDialog: {
        customClass: 'dialog_auto',
        submitUrl: '/oms-api/purchase/OmsPurchaseOrderRpc/cancel.json',
        submitDataHandle: (data) => {
          return {
            id: data.id,
            cancelReason: data.cancelReason,
            cancelRemark: data.cancelRemark,
          }
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [
            {
              key: "cancelReason",
              label: "label_purchase_cancel_reason",
              type: "select",
              enum: "PurchaseCancelReasonEnum",
            },
            {
              key: "cancelRemark",
              label: "label_purchase_cancel_remark",
              attrs: {
                type: 'textarea',
              },
            }
          ],
          rules: {
            'cancelReason': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'cancelRemark': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
          },
        }
      },

      terminationDialog: {
        customClass: 'dialog_auto',
        submitUrl: '/oms-api/purchase/OmsPurchaseOrderRpc/terminate.json',
        submitDataHandle: (data) => {
          return {
            id: data.id,
            cancelReason: data.terminateReason,
            cancelRemark: data.terminateRemark,
          }
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          model: [
            {
              key: "terminateReason",
              label: "label_purchase_terminate_reason",
              type: "select",
              enum: "PurchaseTerminateReasonEnum",
            },
            {
              key: "terminateRemark",
              label: "label_purchase_terminate_remark",
              attrs: {
                type: 'textarea',
              },
            }
          ],
          rules: {
            'terminateReason': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'terminateRemark': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
          },
        }
      },
    }
  },
  watch: {
  },
  computed: {

  },
  created() {
  },
  mounted() {

  },
  methods: {
    reload() {
      this.getSuperTablePage().loadData()
      this.getStatistics()
    },
    option_table_model() {
      return [
        {
          type: "selection",
        },
        {
          key: "code",
          label: "label_purchase_order_code",
          "min-width": 150,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        {
          key: "customerName",
          label: "label_customer",
          "min-width": 130,
          formatter: (r, c, v, i) => this.$formatNameCode(v, r.customerCode),
          "show-overflow-tooltip": true,
        },
        {
          key: "supplierName",
          label: "label_supplier",
          "min-width": 130,
          "show-overflow-tooltip": true,
          formatter: (r, c, v) => this.$formatNameCode(v, r.supplierOnlyCode),
        },
        {
          key: "warehouseName",
          label: "label_purchase_receiving_warehouse",
          "min-width": 130,
          "show-overflow-tooltip": true,
          formatter: (r, c, v) => this.$formatNameCode(v, r.warehouseCode),
        },
        {
          label: "label_purchase_purchase_type",
          key: "purchaseType",
          "min-width": 90,
          "show-overflow-tooltip": true,
          formatter: (r, c, v, i) =>
            this.$enumShow(v, "PurchasePlatformTypeEnum"),
        },
        {
          key: "purchaser",
          label: "label_sku_buyer",
          "min-width": 80,
          "show-overflow-tooltip": true,
        },
        {
          key: "orderNo",
          label: "label_purchase_waybill_number",
          "min-width": 180,
          render: (h, { row, column }) => {
            let divStr = ''
            if (row.omsPurchaseWaybillList) {
              divStr = row.omsPurchaseWaybillList.map(item => {
                return <div>{this.$enumShow(item.logisticsSupplier, "PurchaseOrderLogisticsEnum")}: {item.trackingNumber}</div>
              })

            }
            const addTrackingNumber = e => {
              this.$refs.addTrackingNumberDialog.show(row)
            }
            return (
              <div>
                <div>
                  {row.orderNo ? `${row.purchaseSource}:${row.orderNo}` : ''}
                </div>
                {divStr}
                <div class="clickClass" onClick={addTrackingNumber}>
                  <i class="el-icon-edit"></i>{this.$tt('label_add')}
                </div>
              </div>
            );
          },
        },
        {
          label: "label_platform_order_1688",
          key: "platformOrderNo",
          "min-width": 130,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        {
          label: "label_purchase_warehousing_order_number",
          key: "receivingOrderCode",
          "min-width": 130,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        {
          key: "status",
          label: "label_status",
          width: 100,
          "show-overflow-tooltip": true,
          formatter: (r, c, v, i) =>
            this.$enumShow(v, "PurchaseOrderStatusEnum"),
          render: (h, { row, column }) => {
            let divStr = ''
            if (['WAIT_RECEIVING', 'ARRIVED_WAREHOUSE'].includes(row.status)) {
              divStr = <div>[{row.receivingSkuQty}/{row.skuCount}]</div>
            }
            if (['WAIT_ARRIVAL'].includes(row.status) && ['WAIT_AUDIT'].includes(row.changeStatus)) {
              // 待到货且变更状态为待审核 给出提示
            }
            return (
              <div>
                <div>
                  {this.$enumShow(row.status, "PurchaseOrderStatusEnum")}
                </div>
                {divStr}
              </div>
            );
          },
        },
        {
          label: "label_change_status",
          key: "changeStatus",
          width: 100,
          "show-overflow-tooltip": true,
          formatter: (r, c, v, i) =>
            this.$enumShow(v, "PurchaseAuditStatusEnum"),
        },
        {
          label: "label_purchase_payment_status",
          key: "paymentStatus",
          width: 100,
          "show-overflow-tooltip": true,
          formatter: (r, c, v, i) =>
            this.$enumShow(v, "PurchaseAuditStatusEnum"),
        },
        {
          key: "gmtCreate",
          label: "label_time",
          width: 170,
          render: (h, { row, column }) => {
            return (
              <div>
                <div>
                  {this.$t("label_create")}:{this.$dateFormat(row["gmtCreate"])}
                </div>
                <div>
                  {this.$t("label_update")}:{this.$dateFormat(row["gmtModify"])}
                </div>
              </div>
            );
          },
        },

        {
          type: "operate",
          width: 150,
          operate: [
            {
              label: "label_edit",
              auth: 'oms_purchase_order_edit',
              if: (data) => data.status === 'DRAFT', // 草稿才能编辑
              click: (row) => {
                this.$router.push({
                  path: "/page/oms/purchase/purchaseManage/purchase_order_creation",
                  query: { emitKey, edit: true, id: row.id },
                });
              },
            },
            {
              label: "label_purchase_submission_review",
              if: (data) => data.status === 'DRAFT',// 草稿才能提交审核
              type: "confirm-button",
              urlType: "json",
              url: '/oms-api/purchase/OmsPurchaseOrderRpc/submitDraft.json',
              message: 'label_purchase_submission_review_affirm',
              params: (v) => {
                return { id: v.id }
              },
              done: ['reload', 'tip']
            },

            {
              label: "label_approved",
              if: (data) => data.status === 'WAIT_AUDIT', // 待审核才显示
              click: (row) => {
                this.$refs.auditDialog.show({
                  title: this.$t('label_approved'),
                  url: '/oms-api/purchase/OmsPurchaseOrderRpc/passDraft.json',
                  examine: true,
                  data: row
                })
              }
            },

            {
              label: "label_reject_review",
              if: (data) => data.status === 'WAIT_AUDIT', // 待审核才显示
              click: (row) => {
                this.$refs.auditDialog.show({
                  title: this.$t('label_reject_review'),
                  url: '/oms-api/purchase/OmsPurchaseOrderRpc/rejectDraft.json',
                  examine: false,
                  data: row
                })
              }
            },

            {
              label: "label_apply_pay",
              if: (data) => ['WAIT_ARRIVAL', 'WAIT_RECEIVING', 'ARRIVED_WAREHOUSE', 'COMPLETED'].includes(data.status) && ['NOT_APPLY', 'REJECT'].includes(data.paymentStatus), // 未申请、驳回审核 可申请, // WAIT_ARRIVAL 待到货, WAIT_RECEIVING 待收货, ARRIVED_WAREHOUSE 已到仓, COMPLETED 已完成, 才显示
              click: row => this.$refs.applyPayDialog.show(row, this.$t('label_apply_pay'))
            },
            {
              label: "label_delete",
              if: (data) => (data.status === 'DRAFT' || data.status === 'CANCELED'), // 草稿和已取消的才能删除
              type: "confirm-button",
              urlType: "json",
              url: '/oms-api/purchase/OmsPurchaseOrderRpc/delete.json',
              message: 'label_fms_bank_card_confirm_delete',
              params: (v) => {
                return { idList:[ v.id] }
              },
              done: ['reload', 'tip']
            },

            {
              label: "label_purchase_put_storage",
              if: (data) => data.status === 'WAIT_ARRIVAL', // 待到货才显示
              type: "confirm-button",
              urlType: "json",
              url: '/oms-api/purchase/OmsPurchaseOrderRpc/generateInboundOrder.json',
              message: 'label_purchase_definite_warehousing',
              params: (v) => {
                return { id: v.id }
              },
              done: ['reload', 'tip']
            },
            {
              type: "more",
              items: [
                {
                  label: "label_purchase_change",
                  if: (data) => (data.status === 'WAIT_ARRIVAL' && data.changeStatus !== 'WAIT_AUDIT'), // 待到货且未变更过才显示
                  click: (row) => {
                    this.$router.push({
                      path: "/page/oms/purchase/purchaseManage/purchase_alteration",
                      query: { emitKey, id: row.id },
                    });
                  },
                },
                {
                  label: "label_purchase_termination_purchase_order",
                  if: (data) => ['ARRIVED_WAREHOUSE'].includes(data.status), // 待收货，已到仓才显示
                  click: (row) => {
                    this.$refs.terminationDialog.showNew({
                      title: this.$tt('label_purchase_termination_purchase_order'),
                      data: row,
                    })
                  }
                },
                {
                  label: "label_purchase_cancel_purchase_order",
                  if: (data) => data.status === 'WAIT_ARRIVAL', // 待到货才显示
                  click: (row) => {
                    this.$refs.cancelPurchaseOrderDialog.showNew({
                      title: this.$tt('label_purchase_cancel_purchase_order'),
                      data: row,
                    })
                  }
                },
                {
                  label: "label_restore",
                  if: (data) => data.status === 'CANCELED', // 已取消才显示
                  click: (row) => {
                    this.$confirm(this.$tt('label_purchase_restore_affirm'), this.$tt('label_tip'), {
                      confirmButtonText: this.$tt('label_confirm'),
                      cancelButtonText: this.$tt('label_cancel'),
                      type: 'warning'
                    }).then(() => {
                      this.$ajax({
                        url: '/oms-api/purchase/OmsPurchaseOrderRpc/restore.json',
                        type: "json",
                        data: { id: row.id },
                        success: (res) => {
                          if (res.code === 0) {
                            this.reload()
                            this.$message.success(this.$tt('tip_operate_success'))
                          }
                        }
                      })
                    })
                  }
                },
                {
                  label: "label_purchase_buy_again",
                  if: (data) => data.purchaseType==='GENERAL'&& ['WAIT_ARRIVAL', 'WAIT_RECEIVING', 'ARRIVED_WAREHOUSE', 'COMPLETED'].includes(data.status), // WAIT_ARRIVAL 待到货, WAIT_RECEIVING 待收货, ARRIVED_WAREHOUSE 已到仓, COMPLETED 已完成, 才显示
                  click: (row) => {
                    this.$router.push({
                      path: "/page/oms/purchase/purchaseManage/purchase_order_creation",
                      query: { emitKey, edit: true, repetition: true, id: row.id },
                    });
                  }
                },
                {
                  label: "label_remark",
                  click: (row) => {
                    this.$refs.remarkDialog.show(row)
                  }
                },
                {
                  label: "label_view_detail",
                  // if: (data) => ['WAIT_RECEIVING', 'ARRIVED_WAREHOUSE', 'COMPLETED'].includes(data.status), // WAIT_RECEIVING 待收货, ARRIVED_WAREHOUSE 已到仓, COMPLETED 已完成, 才显示
                  click: (row) => {
                    this.$router.push({
                      path: "/page/oms/purchase/purchaseManage/purchase_order_detail",
                      query: { emitKey, id: row.id },
                    });
                  }
                },

              ],
            },
          ],
        },
      ];
    },
    getStatistics() {
      this.$ajax({
        url: '/oms-api/purchase/OmsPurchaseOrderRpc/countStatus.json',
        success: (res) => {
          Object.keys(this.countByStatus).forEach(key => {
            this.countByStatus[key] = 0
          })
          res.data.rows.forEach(item => {
            this.countByStatus[this.status_map[item.status]] = item.count
          })
        }
      })
    },
    uploadExcelSuccess(response, file, fileList) {
      if (response.code == 0) {
        this.$emitPage("oms>import_manage", 'reload')
        const h = this.$createElement;
        const failureDetails = []
        response.data.failureDetails.forEach(item => {
          failureDetails.push(h('p', null, item))
        })
        const message = h('div', null, [
          h('p', null, `${this.$t('tip_exe_success')}${response.data.successQty}`),
          h('p', null, `${this.$t('tip_exe_failure')}${response.data.failureQty}`),
          h('br', null),
          h('p', null, this.$t('tip_exe_failure_details')),
          ...failureDetails,
        ])
        this.$msgbox({
          title: this.$tt('label_tip'),
          message: message,
          showCancelButton: false,
        })

        this.reload()
        // this.$confirm(this.$tt("tip_importing_confirm_goto_recode_list"), this.$tt('label_tip'), {
        //   type: 'success'
        // }).then(() => {
        //   this.$router.push({
        //     path: '/page/oms/report/import_manage',
        //   });
        // }).catch(() => {

        // });
      } else {
        this.$message.error(response.message || this.$tt('label_upload_fail'));
      }
      if (this.$refs.upload) this.$refs.upload.clearFiles()
    },
    uploadExcelError(response, file, fileList) {
      this.$message.error(this.$tt('label_upload_error'))
    },
    exportExcel() {
      const searchParams = this.$refs.SuperTablePage.getSearchData()
      let idList = []
      if (this.selection) {
        idList = this.selection.map(item => item.id)
      }
      let params = { ...searchParams, idList }
      this.$functionCommon({
        url: "/oms-api/purchase/OmsPurchaseOrderRpc/exportExcel.json",
        data: params, type: 'form',
      })
      // business_function.confirmOperateBaseSelectOrForm.call(this, {
      //   data: {...searchParams,idList },
      //   model: this.option.search.model,
      //   mustData: true,
      //   callback: (selection, data) => {
      //     let params = data
      //     this.$functionCommon({
      //       url: "/oms-api/purchase/OmsPurchaseSupplierRpc/exportExcel.json",
      //       data: params, type: 'form',
      //     })
      //   }
      // })

    },
    // 合并
    merge() {
      if (this.selection) {
        let tag = false
        let tagObj = {
          customerId: {
            value: '',
            msg: 'tip_purchase_merge1',
            tag: false,
          },
          supplierId: {
            value: '',
            msg: 'tip_purchase_merge2',
            tag: false,
          },
          warehouseId: {
            value: '',
            msg: 'tip_purchase_merge3',
            tag: false,
          },
          purchaser: {
            value: '',
            msg: 'tip_purchase_merge4',
            tag: false,
          },
          purchaseSource: {
            value: '',
            msg: 'tip_purchase_merge5',
            tag: false,
          },
          orderNo: {
            value: '',
            msg: 'tip_purchase_merge6',
            tag: false,
          },
        }
        let msgCodes = []
        const idList = this.selection.map(op => {
          if (op.purchaseType === 'ALIBABA') tag = true
          Object.keys(tagObj).forEach(key => {
            if (tagObj[key].value !== '' && op[key] !== tagObj[key].value && !tagObj[key].tag) tagObj[key].tag = true
            tagObj[key].value = op[key]
          })
          msgCodes.push(op.code)
          return op.id
        })
        const key = Object.keys(tagObj).find(key => tagObj[key].tag)
        if (key) return this.$message.error(this.$t(tagObj[key].msg))
        // 以下条件全部相同才能合并
        // 客户 customerId/供货商 supplierId/收货仓 warehouseId/采购员 purchaser/采购渠道来源 purchaseSource/订单号 orderNo
        if (tag) return this.$message.error(this.$tt('label_purchase_merge_error1'))
        if (this.selection.length === 1) return this.$message.error(this.$tt('label_purchase_merge_error2'))
        this.$confirm(this.$t('label_purchase_merge_error3', [`${msgCodes.join('、')}`]), this.$tt('label_tip'), {
          confirmButtonText: this.$tt('label_confirm'),
          cancelButtonText: this.$tt('label_cancel'),
          type: 'warning'
        }).then(() => {
          this.$ajax({
            url: '/oms-api/purchase/OmsPurchaseOrderRpc/mergeDraft.json',
            type: "json",
            data: { idList },
            success: (res) => {
              if (res.code === 0) {
                this.reload()
                this.$message.success(this.$tt('tip_operate_success'))
              }
            }
          })
        })
      } else {
        this.$message.error(this.$tt('tip_please_select_order'))
      }
    },
    // 批量操作
    batchFunc(url, msg) {
      console.log(this.selection);
      if (this.selection && this.selection.length) {
        this.$confirm(msg, this.$tt('label_tip'), {
          confirmButtonText: this.$tt('label_confirm'),
          cancelButtonText: this.$tt('label_cancel'),
          type: 'warning'
        }).then(() => {
          const idList = this.selection.map(op => {
            return op.id
          })
          this.$ajax({
            url,
            type: "json",
            data: { idList },
            success: (res) => {
              if (res.code === 0) {
                this.reload()
                this.$message.success(this.$tt('tip_operate_success'))
              }
            }
          })
        })
      } else {
        this.$message.error(this.$tt('tip_please_select_order'))
      }
    },
    syncOrder() {

      this.$refs.synOrderDialog.show()

    }
  },
  destroyed() {

  }
};
</script>

<style lang="less" scoped>
/deep/.clickClass {
  cursor: pointer;
  color: #2EA7E0;
}
</style>
